<?php
    function __autoload($class_name)
    {
    	include_once('../classes/'.strtolower($class_name).'.php');
    }
    $P = 1; // The current page
    $SapXepTheo = 'MaLoaiSanPham'; // Sort column
    $SapXepTangGiam = 'ASC'; // Sort order
    $qtype = ''; // Search column
    $query = ''; // Search string
    // Get posted data
    if (isset($_POST['page'])) {
            $P = mysql_real_escape_string($_POST['page']);
    }
    if (isset($_POST['sortname'])) {
            $SapXepTheo = mysql_real_escape_string($_POST['sortname']);
    }
    if (isset($_POST['sortorder'])) {
            $SapXepTangGiam = mysql_real_escape_string($_POST['sortorder']);
    }
    if (isset($_POST['qtype'])) {
            $qtype = mysql_real_escape_string($_POST['qtype']);
    }
    if (isset($_POST['query'])) {
            $query = mysql_real_escape_string($_POST['query']);
    }
    if (isset($_POST['rp'])) {
            $SoLoaiSanPham = mysql_real_escape_string($_POST['rp']);
    }
    else $SoLoaiSanPham = 5;

    $query = isset($_POST['query']) ? $_POST['query'] : false;
    $qtype = isset($_POST['qtype']) ? $_POST['qtype'] : false;
    
    $loaisanpham = new loaisanphambs();
    
    $loaisanpham->P = $P;
    $loaisanpham->SoLoaiSanPham = $SoLoaiSanPham;
    $loaisanpham->SapXepTheo = $SapXepTheo;
    $loaisanpham->SapXepTangGiam =$SapXepTangGiam;
    $loaisanpham->qtype = $qtype;
    $loaisanpham->query = $query;
    
    $TongSoTrang = $loaisanpham->totalPageGrid();
    
    $ret_loaisanpham = $loaisanpham->getListGrid();
    
    header("Content-type: text/xml; charset: utf-8;");
    $xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
    $xml .= "<rows>";
    $xml .= "<page>$P</page>";
    $xml .= "<total>$TongSoTrang</total>";
    foreach($ret_loaisanpham as $field)
    {
        $xml .= "<row id='".$field['MaLoaiSanPham']."'>";
    	$xml .= "<cell><![CDATA[".$field['MaLoaiSanPham']."]]></cell>";
    	$xml .= "<cell><![CDATA[".$field['TenLoaiSanPham']."]]></cell>";
    	$xml .= "</row>";
    }
    $xml .= "</rows>";
    echo $xml;